from datetime import datetime
from sqlalchemy import Integer, Column, String, Enum, DateTime, ForeignKey, Float, Boolean, PrimaryKeyConstraint, func
from sqlalchemy.orm import relationship
from sqlalchemy.sql import text
from sqlalchemy.ext.declarative import declarative_base

from src.extension.extension_db import db
from src.model import StudentAnswer

Base = declarative_base()


class User(db.Model):
    """用户表模型"""
    __tablename__ = 'users'
    __table_args__ = (
        PrimaryKeyConstraint('user_id', name='users_pkey'),
    )

    user_id = Column(Integer, nullable=False, autoincrement=True)
    username = Column(String(50), nullable=False, unique=True)
    password = Column(String(255), nullable=False)
    created_at = Column(DateTime, nullable=False, server_default=text('CURRENT_TIMESTAMP(0)'))
    updated_at = Column(DateTime, nullable=False, server_default=text('CURRENT_TIMESTAMP(0)'),
                        server_onupdate=text('CURRENT_TIMESTAMP(0)'))

    student_answers = relationship("StudentAnswer", back_populates="user")



